package org.jeecg.modules.gongqiang.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.gongqiang.entity.AccountPool;
import org.jeecg.modules.gongqiang.entity.AccountVariety;
import org.jeecg.modules.gongqiang.entity.OrderIndexArm;
import org.jeecg.modules.gongqiang.entity.VarietyPool;
import org.jeecg.modules.gongqiang.mapper.*;
import org.jeecg.modules.gongqiang.service.IAccountVarietyService;
import org.jeecg.modules.gongqiang.service.IOrderIndexArmService;
import org.jeecg.modules.gongqiang.vo.AccountVarietyParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 账号币种
 * @Author: jeecg-boot
 * @Date:   2024-10-28
 * @Version: V1.0
 */
@Service
public class AccountVarietyServiceImpl extends ServiceImpl<AccountVarietyMapper, AccountVariety> implements IAccountVarietyService {


    @Autowired
    private IOrderIndexArmService orderIndexArmService;

    @Resource
    private VarietyPoolMapper varietyPoolMapper;


    @Override
    public Result<String> deleteAll(String id)
    {
        this.removeById(id);
        LambdaQueryWrapper<OrderIndexArm> queryWrapperOrderIndexArm=new LambdaQueryWrapper<>();
        queryWrapperOrderIndexArm.eq(OrderIndexArm::getAccountVarietyId,id);
        orderIndexArmService.remove(queryWrapperOrderIndexArm);
        return Result.OK("删除成功!");
    }


    @Override
    public AccountVarietyParams searhInfos(String id)
    {
        LambdaQueryWrapper< AccountVariety> queryWrapperAccountVariety=new LambdaQueryWrapper<>();
        queryWrapperAccountVariety.eq(AccountVariety::getPlatformAccountId,id);
        List<AccountVariety> arrayList=this.list(queryWrapperAccountVariety);
        List<OrderIndexArm> orderIndexArmArray=new ArrayList<>();
        for(AccountVariety temp:arrayList)
        {

            OrderIndexArm orderIndexArm=orderIndexArmService.searhInfos(temp.getId());
            if(oConvertUtils.isEmpty(orderIndexArm))
            {
                orderIndexArm=new OrderIndexArm();
                VarietyPool varietyPool=varietyPoolMapper.selectById(temp.getVarietyId());
                if(oConvertUtils.isEmpty(varietyPool))
                {
                    orderIndexArm.setTradevariety(null);
                }
                else
                {
                    orderIndexArm.setTradevariety(varietyPool.getName());
                }

                orderIndexArmArray.add(orderIndexArm);
            }
            else {
                VarietyPool varietyPool = varietyPoolMapper.selectById(temp.getVarietyId());
                if(oConvertUtils.isEmpty(varietyPool))
                {
                    orderIndexArm.setTradevariety(null);
                }
                else
                {
                    orderIndexArm.setTradevariety(varietyPool.getName());
                }
                orderIndexArmArray.add(orderIndexArm);
            }
        }
        AccountVarietyParams accountVarietyParams=new AccountVarietyParams();
        accountVarietyParams.setOrderIndexArm(orderIndexArmArray);
        return accountVarietyParams;
    }



}
